package com.changwu.cwbase.widget;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PointF;
import android.os.Build;
import android.support.annotation.Nullable;
import android.support.annotation.RequiresApi;
import android.util.AttributeSet;
import android.widget.ImageView;

import com.blankj.utilcode.util.Utils;
import com.changwu.cwbase.R;


@SuppressLint("AppCompatCustomView")
public class VideoImageView extends ImageView {
    private boolean isVideo = false;
    private static Bitmap videoBmp = null;
    private static Bitmap deleteBmp = null;
    private static Paint paint;
    private PointF start = new PointF();// 开始点

    static {
        videoBmp = BitmapFactory.decodeResource(Utils.getApp().getResources(), R.drawable.mrbl_bf);

        paint = new Paint();
        /*paint.setColor(Color.parseColor("#469de6"));
        paint.setStyle(Paint.Style.FILL);*/
    }

    public VideoImageView(Context context) {
        super(context);
    }

    public VideoImageView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public VideoImageView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        TypedArray arr = context.obtainStyledAttributes(attrs, R.styleable.VideoImageView);
        isVideo = arr.getBoolean(R.styleable.VideoImageView_isVideo, true);
        arr.recycle();
    }

    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    public VideoImageView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }


    public void setVideo(boolean isVideo) {
        this.isVideo = isVideo;
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
//        canvas.drawBitmap(deleteBmp, canvas.getWidth() - deleteBmp.getWidth()-ConvertUtils.dp2px(10), ConvertUtils.dp2px(10), null);
        if (isVideo) {
//            canvas.drawRect(canvas.getWidth() - videoBmp.getWidth() - 18, canvas.getHeight() - videoBmp.getHeight(), canvas.getWidth(), canvas.getHeight(), paint);
            canvas.drawBitmap(videoBmp, (canvas.getWidth() - videoBmp.getWidth()) / 2, (canvas.getHeight() - videoBmp.getHeight()) / 2, null);
        }
    }
}
